package cn.zyq.ykb.system.utils;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.alipay.service.schema.util.StringUtil;
import lombok.extern.slf4j.Slf4j;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import static cn.hutool.core.codec.Base32.encodeHex;

public class MD5Util {

	private final static Log log = LogFactory.getLog(StringUtil.class);
	private static MessageDigest digest = null;
	
	/***
	 * MD5加密（生成唯一的MD5值）
	 * @param data
	 * @return
	 * @throws Exception
	 */
	public static String encode(String data) {
		if (digest == null)
			try {
				digest = MessageDigest.getInstance("MD5");
			} catch (NoSuchAlgorithmException nsae) {
				log.error("Failed to load the MD5 MessageDigest."
						+ " We will be unable to function normally.");
				nsae.printStackTrace();
			}
		digest.update(data.getBytes());
		return encodeHex(digest.digest());
	}

	
}